package com.example.xm.service.impl;

import com.example.xm.entity.Fenlei;
import com.example.xm.entity.Huiyuan;
import com.example.xm.exception.SerceiceException;
import com.example.xm.mapper.FenleiMapper;
import com.example.xm.mapper.HuiyuanMapper;
import com.example.xm.service.IFenleiService;
import com.example.xm.service.IHuiyuanService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class HuiyuanService implements IHuiyuanService {
    @Autowired
    HuiyuanMapper shipinfenleiMapper;
    @Override
    public void reg(Huiyuan fenlei) {
        Huiyuan userByName= shipinfenleiMapper.selectByName(fenlei.getName());
//        System.out.println("userByName"+userByName);
        if(userByName!=null){
            throw new SerceiceException(400,"名称已存在");
        }
        shipinfenleiMapper.insert(fenlei);
    }

    @Override
    public PageInfo<Huiyuan> list(String name,Integer page,Integer size) {
        PageHelper.startPage(page,size);
        List<Huiyuan> adminList=  shipinfenleiMapper.selectList(name);
        PageInfo<Huiyuan> adminPageInfo = new PageInfo<Huiyuan>(adminList);
        return adminPageInfo;
    }

    @Override
    public void update(Huiyuan gonggao) {
        shipinfenleiMapper.updateByPrimaryKeySelective(gonggao);
    }

    @Override
    public void delete(int[] intArray) {
        shipinfenleiMapper.delete(intArray);
    }
}
